package com.huanwei.cc.db;

import android.content.Context;
import android.util.Log;

import com.huanwei.cc.bean.FanKui;
import com.j256.ormlite.dao.Dao;

import java.util.List;


/**
 * Created by luoliwen on 16/4/28.
 * 完成对消息数据库的CRUD的操作
 */
public class Z_FanKui_Dao {
    private Context context;
    private Dao<FanKui, Integer> userDao;
    private Z_DataBaseHelper helper;

    public Z_FanKui_Dao(Context context) {
        this.context = context;
        helper = Z_DataBaseHelper.getInstance(context);
        try {
            userDao = helper.getDao(FanKui.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void addMSG(String title, String MSG, String Time, String name


    ) {
        try {
            FanKui life_msg = new FanKui();
            life_msg.setId(String.valueOf(Math.random() * 10));
            life_msg.setTitle(title);
            life_msg.setMSG(MSG);
            life_msg.setTime(Time);
            life_msg.setName(name);
            userDao.create(life_msg);

        } catch (Exception e) {
            e.printStackTrace();
            Log.e("88888", "" + e);
        }
    }

    List<FanKui> XTWUserInfos;

    public List<FanKui> query() {
        try {
            XTWUserInfos = userDao.queryForAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return XTWUserInfos;
    }

    public void deleteUser(FanKui user) {
        try {
            userDao.delete(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
